#include "TcpServer.hpp"
#include "Dict.hpp"
#include "Command.hpp"

void Usage(const std::string &cmd)
{
    std::cerr << "Usage: " << cmd << " port" << std::endl;
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    // Dict d;
    Command cmd;

    std::unique_ptr<TcpServer> usvr = std::make_unique<TcpServer>(port, [&cmd](const std::string &command, InetAddr &addr){
        return cmd.Execute(command, addr);
    });

    // std::unique_ptr<TcpServer> usvr = std::make_unique<TcpServer>(port, [&d](const std::string &word, InetAddr &addr){
    //     return d.Translate(word, addr);
    // });
    usvr->Init();
    usvr->Run();

    return 0;
}